<template>
  <el-table
    :key="tableKey"
    v-loading="listLoading"
    :data="places"
    border
    highlight-current-row
    style="width: 100%;"
  >
    <el-table-column
      label="编号"
      align="center"
      width="90px"
      type="index"
      :index="indexMethod"
    />
    <el-table-column label="名称" align="center" width="220px">
      <template slot-scope="{row}">
        <span>{{ row.placeName }}</span>
      </template>
    </el-table-column>
    <el-table-column label="地块作物，牲畜" align="center">
      <template slot-scope="{row}">
        <span>{{ row.crop }}</span>
      </template>
    </el-table-column>
    <el-table-column
      label="操作"
      align="center"
      min-width="80px"
      width="250px"
      class-name="small-padding fixed-width"
    ><template slot-scope="{row}">
      <el-button type="danger" size="mini" @click="handleDelete(row.placeId)">删除</el-button>
      <el-button type="primary" size="mini" @click="handleModify(row)">编辑</el-button>
      <el-button
        type="success"
        size="mini"
        @click="routePages({placeId: row.placeId}, '/place/image')"
      >详情</el-button>
    </template>
    </el-table-column>
  </el-table>
</template>

<script>
export default {
  name: 'MyTable',
  props: {
    places: {
      type: Array,
      required: true
    },
    listLoading: {
      type: Boolean,
      required: true
    }
  },
  data() {
    return {
      tableKey: 0
    }
  },
  methods: {
    handleModify(row) {
      this.$emit('modify', row)
    },
    handleDelete(placeId) {
      this.$msgbox
        .confirm('您确定要删除这个地块吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        .then(() => {
          this.$emit('remove', placeId)
        })
    },
    indexMethod(index) {
      return index + 1
    },
    routePages(query, url) {
      this.$router.push({
        path: url,
        query
      })
    }
  }
}
</script>

<style scoped>

</style>
